//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.puppy.postgres.demo.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.puppy.postgres.demo.dao.db1.AccessDatasource1Dao;
import cn.puppy.postgres.demo.dao.db2.ResultDatasourceDao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@EnableScheduling
public class TaskService {
    private static final Logger log = LoggerFactory.getLogger(TaskService.class);
    private static final String AAD = "Aad";
    private static final String VAD = "Vad";
    private static final String FCAD = "FCad";
    private static final String MAD = "Mad";
    private static final String QNETAR = "Qnet.ar";
    @Resource
    private AccessDatasource1Dao accessDatasource1Dao;
    @Resource
    private ResultDatasourceDao resultDatasourceDao;

    public TaskService() {
    }

    @PostConstruct
    @Scheduled(
            cron = "0 0/2 * * * ?"
    )
    @Transactional(
            rollbackFor = {RuntimeException.class}
    )
    public void execute() {
        log.info("***********************task-begin**************************");
        log.info("**************************************************************");
        log.info("         shandong luli Steel Co., Ltd.IT DEPT");
        log.info("            Labtory Dept data(zhenshai) synchroize");
        log.info("                Auther:nicepuppy(zlm)");
        log.info("                    DATE:2024/09/10");
        log.info("**************************************************************");
        List<String> itemIdList = new ArrayList();
        int updateCount = 0;

        try {
            List<Map<String, Object>> mdbList = this.accessDatasource1Dao.listMdbTestData((Map)null);
            log.info(String.valueOf(mdbList.size()));
            if (CollectionUtil.isNotEmpty(mdbList)) {
                Iterator var4 = mdbList.iterator();

                while(var4.hasNext()) {
                    Map<String, Object> mdbMap = (Map)var4.next();
                    String sampleNo = mdbMap.get("SampleNo") == null ? "" : mdbMap.get("SampleNo").toString();
                    String element = mdbMap.get("ElementOrChannel") == null ? "" : mdbMap.get("ElementOrChannel").toString();
                    Integer count = this.resultDatasourceDao.countSampleNoAndElement(sampleNo, element);
                    if (count <= 0) {
                        int sampleCodeAndElement = this.resultDatasourceDao.save(mdbMap);
                        updateCount += sampleCodeAndElement;
                    }
                }
            } else {
                System.out.println("空数据！！！");
            }
        } catch (NumberFormatException var10) {
            var10.printStackTrace();
            log.error("出问题了----");
        }

        log.warn("本次定时任务更新数据的条数：" + updateCount);
        log.info("***********************task-end**************************");
        itemIdList.clear();
    }
}
